package com.ahncnk.powermonitor.admin;

import com.ahncnk.powermonitor.admin.auth.interceptor.AuthInterceptor;
import com.ahncnk.powermonitor.commons.exception.ResponsePlainExceptionHandler;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.data.web.config.PageableHandlerMethodArgumentResolverCustomizer;
import org.springframework.data.web.config.SortHandlerMethodArgumentResolverCustomizer;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@SpringBootApplication
@EnableSpringDataWebSupport
@EnableConfigurationProperties
@EnableScheduling
public class AdminApplication implements WebMvcConfigurer {

    public static void main(String[] args) {
        SpringApplication.run(AdminApplication.class, args);
    }

    //所有报扫描不到的组建需要单独申明.
    @Bean
    ResponsePlainExceptionHandler exceptionHandler(){
        return new ResponsePlainExceptionHandler();
    }

    @Resource
    private AuthInterceptor authInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor).addPathPatterns("/api/**");
    }
}
